//
//  ShoppingMallsCell.m
//  Shengzhuli
//
//  Created by FXGuo on 17/3/19.
//  Copyright © 2017年 kamangkeji. All rights reserved.
//

#import "ShoppingMallsCell.h"
#import <UIImageView+WebCache.h>

@interface ShoppingMallsCell()

@property (weak, nonatomic) IBOutlet UIImageView *thumbImageView;
@property (weak, nonatomic) IBOutlet UILabel *priceLab;
@property (weak, nonatomic) IBOutlet UILabel *titleLab;
@property (weak, nonatomic) IBOutlet UILabel *subTitleLab;
@property (weak, nonatomic) IBOutlet UILabel *statusLab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *statusCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *subTitleCons;
@property (weak, nonatomic) IBOutlet UILabel *timeLab;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UIButton *buyCarBtn;

@end

@implementation ShoppingMallsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.subTitleLab.layer.borderColor = [UIColor redColor].CGColor;
}
- (IBAction)buyCarClick:(UIButton *)sender
{
    if (self.buyCarBlock) {
        self.buyCarBlock(self.model);
    }
}
- (void)setIsSeller:(BOOL)isSeller
{
    _isSeller = isSeller;
    self.buyCarBtn.hidden = YES;
}

- (void)setModel:(NormalShopGoodsModel *)model
{
    _model = model;
    [self.thumbImageView sd_setImageWithURL:[NSURL URLWithString:model.thumbnailUrl] placeholderImage:GetImage(@"beijngtu")];
    self.titleLab.text = model.name;
    self.priceLab.text = [NSString stringWithFormat:@"¥%.2f",model.price];
    self.subTitleLab.text = model.subtitle;
    self.timeLab.text = model.access;
    CGSize size = [model.subtitle sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13]}];
    if (size.width > ScreenW-130) {
        self.subTitleCons.constant = ScreenW - 130;
    }else {
        self.subTitleCons.constant = size.width+10;
    }
    if (model.role == 2) {
        self.iconImageView.hidden = NO;
    }else {
        self.iconImageView.hidden = YES;
    }
    if (!self.isSeller) {
        self.statusCons.constant = 0;
        self.statusLab.text = @"";
        return;
    }
    //self.timeLab.hidden = YES;
    self.iconImageView.hidden = YES;
    if (model.status == 0) {
        self.statusLab.text = @"审核中";
    }else if (model.status == 1){
        self.statusLab.text = @"审核通过";
    }else if (model.status == 2){
        self.statusLab.text = @"已下架";
    }else if (model.status == 3){
        self.statusLab.text = @"审核拒绝";
    }
}

@end
